/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import model.domain.Sprint;

/**
 *
 * @author damile
 */
public class SprintConverter implements Converter {

    public SprintConverter(){
        
    }


    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value)
    {

        if (value == null || (value.trim().length() == 0))
        {
            return value;
        }

        Sprint sprint = new Sprint();

        String[] splitedString = value.split(" - ");
        sprint.setSprintID(Integer.parseInt(splitedString[0]));
        sprint.setObjective(splitedString[1]);

        return sprint;
    }

    @Override
      public String getAsString(FacesContext context, UIComponent component, Object value)
      {

       Sprint sprint = null;

        if (value instanceof Sprint)
        {
            sprint = (Sprint)value;

            StringBuilder sprintAsString = new StringBuilder();
            sprintAsString.append(sprint.getSprintID());
            sprintAsString.append(" - ");
            sprintAsString.append(sprint.getObjective());
            String string = sprintAsString.toString();

            return string;
        }
        return "";
    }


}
